package com.xiaomage.handlerdemo

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import kotlinx.android.synthetic.main.activity_handler_update_ui.*

class HandlerUpdateUIActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_handler_update_ui)
        bt_one.setOnClickListener{
            Thread(Runnable {
                Thread.sleep(2000)
                val handler= Handler(this.mainLooper)
                handler.post({
                    tv_content.text="第一种方式更新。uid：${Thread.currentThread().id}"
                })

            }).start()
        }

        bt_two.setOnClickListener{
            MyThread().start()
        }
    }
    inner class MyThread:Thread(){
        override fun run() {
            Thread.sleep(2000)
            //下面这句报错呦
            val handler= Handler()
            handler.post({
                tv_content.text="第2种方式更新。uid：${Thread.currentThread().id}"
            })
        }
    }
}
